var menu={
    init:function(){
        this.loadMenu();
        this.loadEvent();
    },
    /**
     * 当前显示的tab页
     */
    tabObj:'home',
    loadEvent:function(){
        //搜索菜单
        $('#menutitle').keyup(function(){
            var val = this.value;
            menu.initSelectableMenu.treeview('search', [ val, { attribute:'text',ignoreCase: false, exactMatch: false } ]);
        });
        $('#menutitle1').keyup(function(){
            var val = this.value;
            menu.initSelectableMenu1.treeview('search', [ val, { attribute:'text',ignoreCase: false, exactMatch: false } ]);
        });
    },
    save:function(obj){
        var nowtab = $('.layui-tab .layui-this').attr('id');
        var selectRole = [];
        var checkMenu = [];

        var checkRole = [];
        var selectMenu = [];
        if(nowtab == 'home'){//角色对应菜单
            selectRole = menu.initSelectableRole.treeview("getSelected");
            checkMenu = menu.initSelectableMenu.treeview("getChecked");
            if(selectRole.length == 0 || checkMenu == 0){
                layer.msg('您还未选择内容',{time:1000,icon:0});
                if(selectRole.length == 0 && checkMenu == 0){
                    njzxw.shake('#home .layui-field-box');
                }else if(selectRole.length == 0 && checkMenu != 0){
                    njzxw.shake('#home #treeRole');
                }else if(selectRole.length != 0 && checkMenu == 0){
                    njzxw.shake('#home #treeMenu');
                }
                return false;
            }
        }else{//菜单对应角色
            checkRole = menu.initSelectableRole1.treeview("getChecked");
            selectMenu = menu.initSelectableMenu1.treeview("getSelected");
            if(checkRole.length == 0 || selectMenu == 0){
                layer.msg('您还未选择内容',{time:1000,icon:0});
                if(checkRole.length == 0 && selectMenu == 0){
                    njzxw.shake('#profile .layui-field-box');
                }else if(checkRole.length == 0 && selectMenu != 0){
                    njzxw.shake('#profile #treeRole1');
                }else if(checkRole.length != 0 && selectMenu == 0){
                    njzxw.shake('#profile #treeMenu1');
                }
                return false;
            }
        }

        //进行 转换参数
        var selectRole1 = ",";
        if(selectRole.length != 0){
            for(var i=0;i<selectRole.length;i++){
                selectRole1 +=  selectRole[i].id+",";
            }
        }
        var checkMenu1 = ",";
        if(checkMenu.length != 0){
            for(var i=0;i<checkMenu.length;i++){
                if(checkMenu[i].ispower){
                    checkMenu1 +=  checkMenu[i].id+",";
                }
            }
        }

        var checkRole1 = ",";
        if(checkRole.length != 0){
            for(var i=0;i<checkRole.length;i++){
                checkRole1 +=  checkRole[i].id+",";
            }
        }

        var selectMenu1 = ",";
        if(selectMenu.length != 0){
            for(var i=0;i<selectMenu.length;i++){
                if(selectMenu[i].ispower){
                    selectMenu1 +=  selectMenu[i].id+",";
                }
            }
        }

        njzxw.ajax({
            url:URL.INDEX.SAVEPOWER,
            data:{
                nowtab:nowtab,
                checkRole:checkRole1,
                selectMenu:selectMenu1,
                selectRole:selectRole1,
                checkMenu:checkMenu1
            },
            fun:function(a,b){

                if(a){
                    //进行清除选择的
                    if(b.state == 1){
                        njzxw.alert({
                            msg:b.msg,
                            fun:function () {
                                parent.index.refresh();
                            }
                        })
                    }else{
                        njzxw.alert({
                            msg:b.msg,
                            error:true
                        })
                    }
                }else{
                    njzxw.alert({
                        msg:'权限保存失败',
                        error:true
                    })
                }
            }
        });
        return false;
    },
    /**
     * 菜单对象
     */
    initSelectableMenu:null,
    initSelectableMenu1:null,
    initSelectableRole:null,
    initSelectableRole1:null,
    /**
     * 加载菜单
     */
    loadMenu:function(){
        //加载菜单
        njzxw.ajax({
            url:URL.INDEX.LOADMENUDATA,
            fun:function(a,b){
                console.log("获取菜单信息",b);
                if(a){
                    if(b.state == 1){
                        var data = b.menuData;
                        var cnt = data.length;
                        var href = "#";
                        var json = [];
                        for(var i=0;i<cnt;i++){//取层级关系 第一级
                            var icon0 = data[i].icon;
                            var id0 = data[i].id;
                            var levels0 = data[i].levels;
                            var menu_name0 = data[i].menu_name;
                            var supper_id0 = data[i].supper_id;
                            var menu_url0 = data[i].menu_url;
                            var da0 = {};

                            da0.isShowCheck = 0;
                            if(menu_url0 == ''){
                                da0.icon = 'glyphicon glyphicon-folder-close';
                                da0.selectedIcon = 'glyphicon glyphicon-folder-close';
                            }else{
                                da0.icon = 'glyphicon glyphicon-list';
                            }
                            if(supper_id0 == 0 || supper_id0 == '' || supper_id0 == undefined){//第一级菜单
                                da0.text = menu_name0;
                                da0.id = id0;
                                da0.nodeId = id0;
                                da0.parentId = 0;
                                da0.supper_id = supper_id0;
                                var tags0 = 0;
                                var nodes0 = [];
                                //进行下级循环
                                for(var i1=0;i1<cnt;i1++){//第二级循环
                                    var icon1 = data[i1].icon;
                                    var id1 = data[i1].id;
                                    var levels1 = data[i1].levels;
                                    var menu_name1 = data[i1].menu_name;
                                    var supper_id1 = data[i1].supper_id;
                                    var menu_url1 = data[i1].menu_url;
                                    var da1 = {};
                                    da1.isShowCheck = 0;
                                    if(menu_url1 == ''){
                                        da1.icon = 'glyphicon glyphicon-folder-close';
                                        da1.selectedIcon = 'glyphicon glyphicon-folder-close';
                                    }else{
                                        da1.icon = 'glyphicon glyphicon-list';
                                    }
                                    if(supper_id1 == id0){
                                        da1.text = menu_name1;
                                        da1.id = id1;
                                        da1.nodeId = id1;
                                        da1.parentId = supper_id1;
                                        da1.supper_id = supper_id1;
                                        var tags1 = 0;
                                        var nodes1 = [];

                                        for(var i2=0;i2<cnt;i2++){//第三级循环
                                            var icon2 = data[i2].icon;
                                            var id2 = data[i2].id;
                                            var levels2 = data[i2].levels;
                                            var menu_name2 = data[i2].menu_name;
                                            var supper_id2 = data[i2].supper_id;
                                            var menu_url2 = data[i2].menu_url;
                                            var da2 = {};
                                            da2.isShowCheck = 0;
                                            if( menu_url2 == ''){
                                                da2.icon = 'glyphicon glyphicon-folder-close';
                                                da2.selectedIcon = 'glyphicon glyphicon-folder-close';
                                            }else{
                                                da2.icon = 'glyphicon glyphicon-list';
                                            }
                                            if(supper_id2 == id1){
                                                da2.text = menu_name2;
                                                da2.nodeId = id2;
                                                da2.parentId = supper_id2;
                                                da2.id = id2;
                                                da2.supper_id = supper_id2;
                                                var tags2 = 0;
                                                var nodes2 = [];

                                                for(var i3=0;i3<cnt;i3++){//第三级循环
                                                    var icon3 = data[i3].icon;
                                                    var id3 = data[i3].id;
                                                    var levels3 = data[i3].levels;
                                                    var menu_name3 = data[i3].menu_name;
                                                    var supper_id3 = data[i3].supper_id;
                                                    var menu_url3 = data[i3].menu_url;
                                                    var da3 = {};
                                                    da3.isShowCheck = 0;
                                                    if( menu_url3 == ''){
                                                        da3.icon = 'glyphicon glyphicon-folder-close';
                                                        da3.selectedIcon = 'glyphicon glyphicon-folder-close';
                                                    }else{
                                                        da3.icon = 'glyphicon glyphicon-list';
                                                    }
                                                    if(supper_id3 == id2){
                                                        da3.text = menu_name3;
                                                        da3.nodeId = id3;
                                                        da3.parentId = supper_id3;
                                                        da3.id = id3;
                                                        da3.supper_id = supper_id3;
                                                        var tags3 = 0;
                                                        var nodes3 = [];




                                                        if(tags3 == 0){
                                                            da3.href = '#'+id3;
                                                        }
                                                        if(nodes3.length != 0){
                                                            var powerNodes = menu.loadPower(b.powerData,id3);
                                                            nodes3 = nodes3.concat(powerNodes);
                                                            da3.nodes = nodes3;
                                                        }else{//添加权限菜单
                                                            nodes3 = menu.loadPower(b.powerData,id3);
                                                            if(nodes3.length != 0){
                                                                da3.nodes = nodes3;
                                                            }
                                                        }
                                                        da3.tags = [''+nodes3.length+''];
                                                        da3.isdelete = data[i3].isdelete;
                                                        nodes2.push(da3);
                                                        tags2 ++;
                                                    }
                                                }


                                                if(tags2 == 0){
                                                    console.log("id2:",id2);

                                                    da2.href = '#'+id2;
                                                }
                                                if(nodes2.length != 0){
                                                    var powerNodes = menu.loadPower(b.powerData,id2);
                                                    nodes2 = nodes2.concat(powerNodes);
                                                    da2.nodes = nodes2;
                                                }else{//添加权限菜单
                                                    nodes2 = menu.loadPower(b.powerData,id2);
                                                    if(nodes2.length != 0){
                                                        da2.nodes = nodes2;
                                                    }
                                                }
                                                da2.tags = [''+nodes2.length+''];
                                                da2.isdelete = data[i2].isdelete;
                                                nodes1.push(da2);
                                                tags1 ++;

                                            }
                                        }

                                        if(tags1 == 0){
                                            da1.href = '#'+id1;
                                        }
                                        if(nodes1.length != 0){
                                            var powerNodes = menu.loadPower(b.powerData,id1);
                                            nodes1 = nodes1.concat(powerNodes);
                                            da1.nodes = nodes1;
                                        }else{//添加权限菜单
                                            nodes1 = menu.loadPower(b.powerData,id1);
                                            if(nodes1.length != 0){
                                                da1.nodes = nodes1;
                                            }
                                        }
                                        da1.tags = [''+nodes1.length+''];
                                        da1.isdelete = data[i1].isdelete;
                                        nodes0.push(da1);
                                        tags0 ++;
                                    }
                                }

                                if(tags0 == 0){
                                    da0.href = '#'+id0;
                                }
                                if(nodes0.length != 0){
                                    var powerNodes = menu.loadPower(b.powerData,id0);
                                    nodes0 = nodes0.concat(powerNodes);
                                    da0.nodes = nodes0;
                                }else{//添加权限菜单
                                    nodes0 = menu.loadPower(b.powerData,id0);
                                    if(nodes0.length != 0){
                                        da0.nodes = nodes0;
                                    }
                                }
                                da0.tags = [''+nodes0.length+''];
                                da0.isdelete = data[i].isdelete;

                                json.push(da0);
                            }
                        }
                        console.log('获取菜单睡觉：',json);
                        menu.initSelectableMenu = $('#treeMenu').treeview({
                            color: "#428bca",
                            expandIcon: 'glyphicon glyphicon-chevron-right',
                            collapseIcon: 'glyphicon glyphicon-chevron-down',
                            nodeIcon: 'glyphicon glyphicon-bookmark',
                            showIcon:true,
                            showTags: true,
                            highlightSelected:false,
                            showCheckbox:true,
                            showDeleteIcon:true,
                            showModifyIcon:true,
                            multiSelect:true,
                            levels: 1,
                            data: json,
                            onNodeSelected: function(event, node) {
                                var checkableNodes = menu.initSelectableMenu.treeview('search', [ node.id, { attribute:'supper_id',ignoreCase: false, exactMatch: true } ]);
                                menu.initSelectableMenu.treeview('checkNode', [ checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
                                for(var i = 0;i<checkableNodes.length;i++){
                                    var checkableNodes1 = menu.initSelectableMenu.treeview('search', [ checkableNodes[i].id, { attribute:'supper_id',ignoreCase: false, exactMatch: true } ]);
                                    menu.initSelectableMenu.treeview('checkNode', [ checkableNodes1, { silent: $('#chk-check-silent').is(':checked') }]);
                                }
                                menu.initSelectableMenu.treeview('clearSearch');
                            },
                            onNodeUnselected: function (event, node) {
                                var checkableNodes = menu.initSelectableMenu.treeview('search', [ node.id, { attribute:'supper_id',ignoreCase: false, exactMatch: true } ]);
                                menu.initSelectableMenu.treeview('uncheckNode', [ checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
                                for(var i = 0;i<checkableNodes.length;i++){
                                    var checkableNodes1 = menu.initSelectableMenu.treeview('search', [ checkableNodes[i].id, { attribute:'supper_id',ignoreCase: false, exactMatch: true } ]);
                                    menu.initSelectableMenu.treeview('uncheckNode', [ checkableNodes1, { silent: $('#chk-check-silent').is(':checked') }]);
                                }
                                menu.initSelectableMenu.treeview('clearSearch');
                            },
                            //勾选事件
                            onNodeChecked:function(event, node){
                                var nodesCheck = menu.initSelectableRole.treeview("getSelected");
                                if(nodesCheck.length == 0){
                                    layer.msg('请先选择角色',{time:1000,icon:0});
                                    menu.initSelectableMenu.treeview('uncheckAll');
                                }else{

                                }
                            },
                            //取消勾选事件
                            onNodeUnchecked:function(event, node){
                                //common.log(node);
                            },
                            onNodeDelete:function(event, node){
                                //删除菜单
                                menu.deleteMenu(node);
                            },
                            onNodeModify:function(event, node){
                                menu.modifyMenu(node);
                            }
                        });
                        menu.initSelectableMenu1 = $('#treeMenu1').treeview({
                            color: "#428bca",
                            expandIcon: 'glyphicon glyphicon-chevron-right',
                            collapseIcon: 'glyphicon glyphicon-chevron-down',
                            nodeIcon: 'glyphicon glyphicon-bookmark',
                            showIcon:true,
                            showTags: true,
                            showCheckbox:false,
                            highlightSelected:true,
                            showModifyIcon:true,
                            showDeleteIcon:true,
                            levels: 1,
                            data: json,
                            onNodeSelected: function(event, node) {
                                if(!node.ispower){
                                    return;
                                }
                                njzxw.ajax({
                                    url:URL.INDEX.LOADMENUROLE,
                                    data:{
                                        menu_id:node.id
                                    },
                                    fun:function(a,b){
                                        if(a){
                                            //进行清除选择的
                                            if(b.state == 1){
                                                //清除所有已选择的
                                                menu.initSelectableRole1.treeview('uncheckAll');
                                                var cnt = b.data.length;

                                                for(var i=0;i<cnt;i++){
                                                    var checkableNodes = menu.initSelectableRole1.treeview('search', [ b.data[i].role_id, { attribute:'id',ignoreCase: false, exactMatch: true } ])
                                                    if(checkableNodes.length == 1){
                                                        menu.initSelectableRole1.treeview('checkNode', [ checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
                                                    }
                                                }
                                                menu.initSelectableRole1.treeview('clearSearch');
                                            }else{
                                                njzxw.alert({
                                                    msg:'操作失败',
                                                    error:true
                                                });
                                            }
                                        }else{
                                            njzxw.alert({
                                                msg:'操作失败',
                                                error:true
                                            });
                                        }
                                    }
                                });
                            },
                            onNodeUnselected: function (event, node) {
                                //common.log(node);
                                menu.initSelectableRole1.treeview('uncheckAll');
                            },
                            //勾选事件
                            onNodeChecked:function(event, node){
                                //common.log(node);
                            },
                            //取消勾选事件
                            onNodeUnchecked:function(event, node){
                                //common.log(node);
                            },
                            onNodeDelete:function(event, node){
                                //删除菜单
                                menu.deleteMenu(node);
                            },
                            onNodeModify:function(event, node){
                                menu.modifyMenu(node);
                            }
                        });

                        //加载角色信息
                        var dataRole = b.roleData;
                        var cntRole = dataRole.length;
                        var hrefRole = "#";
                        var jsonRole = [];
                        for(var i=0;i<cntRole;i++){//取层级关系 第一级
                            var da = {
                                id:dataRole[i].id,
                                text:dataRole[i].role_name,
                                isdelete:dataRole[i].isdelete
                            };
                            jsonRole.push(da);
                        }
                        menu.initSelectableRole = $('#treeRole').treeview({
                            color: "#428bca",
                            expandIcon: 'glyphicon glyphicon-chevron-right',
                            collapseIcon: 'glyphicon glyphicon-chevron-down',
                            nodeIcon: 'glyphicon glyphicon-bookmark',
                            showIcon:false,
                            showTags: false,
                            showDeleteIcon:true,
                            levels: 1,
                            data: jsonRole,
                            onNodeSelected: function(event, node) {
                                //进行加载对应的事件信息，加载该角色对应那些菜单与权限
                                var startTime_ = new Date();
                                console.log("开始请求后台",startTime_,startTime_.getTime());
                                njzxw.ajax({
                                    url:URL.INDEX.LOADROLEMENU,
                                    data:{
                                        role_id:node.id
                                    },
                                    fun:function(a,b){
                                        var endAjaxTime_ = new Date();
                                        console.log("请求后台执行完毕",endAjaxTime_,endAjaxTime_.getTime(),endAjaxTime_.getTime()-startTime_.getTime());
                                        if(a){
                                            //进行清除选择的
                                            if(b.state == 1){
                                                //清除所有已选择的
                                                var endAjaxTime_1 = new Date();
                                                console.log("请求后台执行清除开始",endAjaxTime_1,endAjaxTime_1.getTime(),endAjaxTime_1.getTime()-endAjaxTime_.getTime());
                                                menu.initSelectableMenu.treeview('uncheckAll');
                                                var endAjaxTime_2 = new Date();
                                                console.log("请求后台执行清除结束",endAjaxTime_2,endAjaxTime_2.getTime(),endAjaxTime_2.getTime()-endAjaxTime_1.getTime());
                                                //重新进行选择勾选
                                                var cnt = b.data.length;
                                                console.log("请求后台执行清除结束",b.data);
                                                var json_ = menu.initSelectableMenu.treeview('getEnabled');
                                                // console.log("请求后台执行清除结束",json_);
                                                var cnt_ = json_.length;
                                                for(var i=0;i<cnt;i++){
                                                    var checkableNodes = menu.getNodeId(json_,'power_id',b.data[i].authority_id);

                                                    // var checkableNodes = menu.initSelectableMenu.treeview('search', [ b.data[i].authority_id, { attribute:'power_id',ignoreCase: false, exactMatch: true } ])
                                                    // console.log('===|',checkableNodes);
                                                    if(checkableNodes != null){
                                                        menu.initSelectableMenu.treeview('checkNode', [ checkableNodes, { silent: true }]);
                                                        // menu.selectMenuObj = [];
                                                        // menu.selectMenu(checkableNodes[0].supper_id,menu.initSelectableMenu,'id');
                                                    }
                                                }
                                                var endAjaxTime_3 = new Date();
                                                console.log("执行js赋值结束",endAjaxTime_3,endAjaxTime_3.getTime(),endAjaxTime_3.getTime()-endAjaxTime_2.getTime());
                                                menu.initSelectableMenu.treeview('expandAll');
                                                var endAjaxTime_4 = new Date();
                                                console.log("执行js赋值结束",endAjaxTime_4,endAjaxTime_4.getTime(),endAjaxTime_4.getTime()-endAjaxTime_3.getTime());
                                                menu.initSelectableMenu.treeview('clearSearch');
                                            }else{
                                                njzxw.alert({
                                                    error:true,
                                                    msg:'菜单加载错误'
                                                });
                                            }
                                        }else{
                                            njzxw.alert({
                                                error:true,
                                                msg:'菜单加载错误'
                                            });
                                        }
                                    }
                                });
                            },
                            onNodeUnselected: function (event, node) {
                                menu.initSelectableMenu.treeview('uncheckAll');
                            },
                            //勾选事件
                            onNodeChecked:function(event, node){
                                //common.log(node);
                                //
                            },
                            //取消勾选事件
                            onNodeUnchecked:function(event, node){
                                //common.log(node);
                            },
                            onNodeDelete:function(event, node){
                                //menu.initSelectableMenu.treeview('remove', { silent: $('#chk-check-silent').is(':checked') });
                                menu.deleteRole(node);
                            }
                        });
                        console.log("jsonRole:",menu.initSelectableRole);
                        menu.initSelectableRole1 = $('#treeRole1').treeview({
                            color: "#428bca",
                            expandIcon: 'glyphicon glyphicon-chevron-right',
                            collapseIcon: 'glyphicon glyphicon-chevron-down',
                            nodeIcon: 'glyphicon glyphicon-bookmark',
                            showIcon:false,
                            showTags: true,
                            highlightSelected:false,
                            showCheckbox:true,
                            showDeleteIcon:true,
                            levels: 1,
                            data: jsonRole,
                            onNodeSelected: function(event, node) {
                                //common.log(node);
                            },
                            onNodeUnselected: function (event, node) {
                                //common.log(node);
                            },
                            //勾选事件
                            onNodeChecked:function(event, node){
                                //common.log(node);
                            },
                            //取消勾选事件
                            onNodeUnchecked:function(event, node){
                                //common.log(node);
                            },
                            onNodeDelete:function(event, node){
                                //menu.initSelectableMenu.treeview('remove', { silent: $('#chk-check-silent').is(':checked') });
                                menu.deleteRole(node);
                            }
                        });
                    }else{
                        njzxw.alert({
                            error:true,
                            msg:'菜单加载错误'
                        });
                    }
                }else{
                    njzxw.alert({
                        error:true,
                        msg:'菜单加载错误'
                    });
                }
            }
        });
    },
    /**
     * 删除菜单操作
     * @param node
     */
    deleteMenu:function(node){
        njzxw.alert({
            msg:'确定需要进行删除吗？',
            type:'confirm',
            fun:function(a){
                if(a){
                    njzxw.ajax({
                        url:URL.INDEX.DELETEMENU,
                        data:{
                            menu_id:node.id
                        },
                        fun:function(a,b){
                            if(a){
                                //进行清除选择的
                                if(b.state == 1){
                                    njzxw.alert({
                                        msg:b.msg,
                                        fun:function(){
                                            parent.index.refresh();
                                        }
                                    });
                                }else{
                                    njzxw.alert({
                                        msg:b.msg,
                                        error:true
                                    });
                                }
                            }else{
                                njzxw.alert({
                                    msg:'操作失败',
                                    error:true
                                });
                            }
                        }
                    });
                }
            }
        });
    },
    /**
     * 删除角色信息
     */
    deleteRole:function(node){
        njzxw.alert({
            msg:'确定需要进行删除吗？',
            type:'confirm',
            fun:function(a){
                if(a){
                    njzxw.ajax({
                        url:URL.INDEX.REMOVEROLE,
                        data:{
                            role_id:node.id
                        },
                        fun:function(a,b){
                            if(a){
                                //进行清除选择的
                                if(b.state == 1){
                                    njzxw.alert({
                                        msg:b.msg,
                                        fun:function(){
                                            parent.index.refresh();
                                        }
                                    });
                                }else{
                                    njzxw.alert({
                                        msg:b.msg,
                                        error:true
                                    });
                                }
                            }else{
                                njzxw.alert({
                                    msg:'操作失败',
                                    error:true
                                });
                            }
                        }
                    });
                }
            }
        });
    },
    selectMenuObj:[],
    selectMenu:function(sup,initSelectableMenu,attr){
        var checkableNodes1 = initSelectableMenu.treeview('search', [ sup, { attribute:attr,ignoreCase: false, exactMatch: true } ])

        if(menu.selectMenuObj.indexOf(sup) != -1){//已结包含了，不在操作
            if(checkableNodes1.length == 1){
                var sup1 = checkableNodes1[0].supper_id;
                if(sup1 != 0 && sup1 != undefined){
                    menu.selectMenuObj.push(sup);
                    menu.selectMenu(sup1,initSelectableMenu,attr);
                }
            }
        }else{
            if(checkableNodes1.length == 1){
                initSelectableMenu.treeview('checkNode', [ checkableNodes1, { silent: $('#chk-check-silent').is(':checked') }]);
                var sup1 = checkableNodes1[0].supper_id;
                if(sup1 != 0 && sup1 != undefined){
                    menu.selectMenuObj.push(sup);
                    menu.selectMenu(sup1,initSelectableMenu,attr);
                }
            }
        }
    },
    /**
     * 添加权限信息
     *
     * @param data
     * @param menu_id
     * @returns {Array}
     */
    loadPower:function(data,menuid){
        var cnt = data.length;
        var href = "#";
        var json = [];

        for(var i=0;i<cnt;i++){
            var menu_id = data[i].menu_id;
            var name = data[i].name;
            var id = data[i].id;
            var isdelete = 0;
            var da = {};
            if(menuid == menu_id){
                da.text = name;
                da.href = href;
                da.supper_id = menu_id;
                da.id = id;
                da.nodeId = id;
                da.parentId = menu_id;
                da.power_id = id;
                da.isdelete = isdelete;
                da.isShowCheck = 1;
                da.isShowModify = 0;
                da.ispower = true;
                da.icon = 'glyphicon glyphicon-lock';
                da.selectedIcon = 'glyphicon glyphicon-lock';
                json.push(da);
            }
        }
        return json;
    },
    addMenu:function(){
        njzxw.openWindow({
            id:'addMenu',
            title:'新增菜单',
            content:'sys/jurisdiction/menu.html'
        })
    },
    //修改菜单
    modifyMenu:function(node){
        njzxw.openWindow({
            id:'modifymenu'+node.id,
            title:'修改菜单',
            cacheFun:'addMenu.cache',
            content:'sys/jurisdiction/menu.html?id='+node.id
        });
    },
    /**
     * 添加角色
     */
    addRole:function(){
        layer.prompt({title: '请输入角色名'}, function(val, index){
            //layer.close(index);
            njzxw.ajax({
                url:URL.INDEX.ADDROLE,
                data:{
                    role_name:val
                },
                fun:function(a,b){
                    if(a){
                        //进行清除选择的
                        if(b.state == 1){
                            layer.close(index);
                            njzxw.alert({
                                msg:b.msg,
                                fun:function(){
                                    parent.index.refresh();
                                }
                            });
                        }else{
                            njzxw.alert({
                                msg:b.msg,
                                error:true
                            });
                        }
                    }else{
                        njzxw.alert({
                            msg:'操作失败',
                            error:true
                        });
                    }
                }
            });
        });
    },
    getNodeId:function(json_,key,val){
        var cnt_ = json_.length;
        for(var j=0;j<cnt_;j++){
            if(json_[j][key] == val){
                return json_[j].nodeId;
            }
        }
        return null;
    }
};